#-------------------------------------------------------------------------------
# LDL Lib/Makefile 
#-------------------------------------------------------------------------------

LIBRARY = libldl
VERSION = 2.2.4
SO_VERSION = 2

default: library

include ../../SuiteSparse_config/SuiteSparse_config.mk

# LDL depends on SuiteSparse_config
LDLIBS += -lsuitesparseconfig

# compile and install in SuiteSparse/lib
library:
	$(MAKE) install INSTALL=$(SUITESPARSE)

I = -I../../SuiteSparse_config -I../Include

C = $(CC) $(CF) $(I)

all: library

OBJ = ldl.o ldll.o

ldl.o: ../Source/ldl.c ../Include/ldl.h
	$(C) -c ../Source/ldl.c -o ldl.o

ldll.o: ../Source/ldl.c ../Include/ldl.h
	$(C) -DLDL_LONG -c ../Source/ldl.c -o ldll.o

$(AR_TARGET): $(OBJ)
	$(ARCHIVE) $@ $^
	- $(RANLIB) $@

distclean: purge

purge: clean
	- $(RM) -r $(PURGE)

clean:
	- $(RM) -r $(CLEAN)

# install LDL
install: $(AR_TARGET) $(INSTALL_LIB)/$(SO_TARGET)

$(INSTALL_LIB)/$(SO_TARGET): $(OBJ)
	@mkdir -p $(INSTALL_LIB)
	@mkdir -p $(INSTALL_INCLUDE)
	@mkdir -p $(INSTALL_DOC)
	$(CC) $(SO_OPTS) $^ -o $@ $(LDLIBS)
	( cd $(INSTALL_LIB) ; ln -sf $(SO_TARGET) $(SO_PLAIN) )
	( cd $(INSTALL_LIB) ; ln -sf $(SO_TARGET) $(SO_MAIN) )
	$(CP) ../Include/ldl.h $(INSTALL_INCLUDE)
	$(CP) ../Doc/ldl_userguide.pdf $(INSTALL_DOC)
	$(CP) ../README.txt $(INSTALL_DOC)/LDL_README.txt
	chmod 755 $(INSTALL_LIB)/$(SO_TARGET)
	chmod 644 $(INSTALL_INCLUDE)/ldl.h
	chmod 644 $(INSTALL_DOC)/ldl_userguide.pdf
	chmod 644 $(INSTALL_DOC)/LDL_README.txt

# uninstall LDL
uninstall:
	$(RM) $(INSTALL_LIB)/$(SO_TARGET)
	$(RM) $(INSTALL_LIB)/$(SO_PLAIN)
	$(RM) $(INSTALL_LIB)/$(SO_MAIN)
	$(RM) $(INSTALL_INCLUDE)/ldl.h
	$(RM) $(INSTALL_DOC)/ldl_userguide.pdf
	$(RM) $(INSTALL_DOC)/LDL_README.txt

